package com.moxing.admin.service.impl;

import com.moxing.admin.common.constant.RedisConstant;
import com.moxing.admin.common.utils.RedisUtil;
import com.moxing.admin.mapper.Mysql.OrderMysqlMapper;
import com.moxing.admin.mapper.Oracle.OrderOracleMapper;
import com.moxing.admin.service.OrderService;
import com.moxing.admin.common.entity.Order;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;


@Slf4j
@Service(value = "OrderService")
public class OrderServiceImpl implements OrderService {

    @Autowired
    private OrderOracleMapper orderOracleMapper;


    @Autowired
    private OrderMysqlMapper orderMysqlMapper;

    @Override
    public List<Order> getOrderMysql() {
        return orderMysqlMapper.getAll();
    }

    @Override
    public List<Order> getOrderOracle() {
        return orderOracleMapper.getAll();
    }

    @Override
    public Order getOrderById(String id) {
        return orderOracleMapper.getOrderById(id);
    }

    @Override
    public Order getOrderByRedis(String id) {
        Order order = (Order) RedisUtil.get(RedisConstant.ORDERID_KEY + id);
        if (order == null) {
            order = orderOracleMapper.getOrderById(id);
            RedisUtil.setValueAndSeconds(RedisConstant.ORDERID_KEY + id,order,RedisConstant.KEY_TOKEN_EXPIRE_TIME);
        }
        return order;
    }
}
